package com.slm.report.view.data;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.slm.report.databinding.ViewHistoryVisionBinding;

/**
 * @ProjectName: My Application
 * @Package: com.slm.report.view.data
 * @ClassName: HistoryVisionContentView
 * @Description: java类作用描述
 * @Author: 王丹丹
 * @CreateDate: 2020/6/2 14:03
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/6/2 14:03
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class HistoryVisionContentView extends BaseContentView {
    ViewHistoryVisionBinding historyVisionBinding = null;

    public HistoryVisionContentView(Context context) {
        super(context);
        historyVisionBinding = ViewHistoryVisionBinding.inflate(LayoutInflater.from(getContext()), this, true);
        historyVisionBinding.rgSex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(historyVisionBinding.rgSex.getCheckedRadioButtonId());
                contentDataBean.setContent(radioButton.getText().toString());
                if ("是".equals(radioButton.getText().toString())) {
                    historyVisionBinding.dataLl.setVisibility(VISIBLE);
                } else {
                    historyVisionBinding.dataLl.setVisibility(GONE);
                }
                contentDataBean.getValueMap().put("key", radioButton.getText().toString());
            }
        });
        historyVisionBinding.lTv.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                String leftValue = s.toString();
                contentDataBean.getValueMap().put("left", leftValue);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        historyVisionBinding.rTv.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                String rightValue = s.toString();
                contentDataBean.getValueMap().put("right", rightValue);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    @Override
    void upDataContent() {
        historyVisionBinding.titleTv.setText(contentDataBean.getTitleStr());
        historyVisionBinding.lTv.setText(contentDataBean.getValueMap().get("left"));
        historyVisionBinding.rTv.setText(contentDataBean.getValueMap().get("right"));
        if ("是".equals(contentDataBean.getValueMap().get("key"))) {
            historyVisionBinding.dataLl.setVisibility(VISIBLE);
        }else{
            historyVisionBinding.dataLl.setVisibility(GONE);
        }
        if (isEdit) {
            historyVisionBinding.contentTv.setVisibility(GONE);
            historyVisionBinding.rgSex.setVisibility(VISIBLE);
            if ("是".equals(contentDataBean.getValueMap().get("key"))) {
                historyVisionBinding.yesRadio.setChecked(true);
            } else {
                historyVisionBinding.noRadio.setChecked(true);
                contentDataBean.getValueMap().put("key", "否");
            }
        } else {
            historyVisionBinding.contentTv.setVisibility(VISIBLE);
            historyVisionBinding.rgSex.setVisibility(GONE);
            historyVisionBinding.contentTv.setText(contentDataBean.getValueMap().get("key"));
            historyVisionBinding.lTv.setHint("");
            historyVisionBinding.rTv.setHint("");
            historyVisionBinding.lTv.setFocusable(false);
            historyVisionBinding.lTv.setFocusableInTouchMode(false);
            historyVisionBinding.rTv.setFocusable(false);
            historyVisionBinding.rTv.setFocusableInTouchMode(false);
        }
    }
}
